﻿using SBlogCore.Common.Models;
using SqlSugar;
using System.Data;
using System.Linq.Expressions;

namespace SBlogCore.Common.DatabaseAccessor.Repositorys.SQLSuger
{
    [SkipScan]
    public interface ISqlSugerRepository<T> where T : class, new()
    {
        Task<T> QueryById(object objId);
        Task<T> QueryById(object objId, bool blnUseCache = false);
        Task<List<T>> QueryByIDs(object[] lstIds);
        Task<int> Add(T entity);
        Task<int> Add(T entity, Expression<Func<T, object>> insertColumns = null);
        Task<int> Add(List<T> listEntity);
        Task<bool> Update(T entity);
        Task<bool> Update(T entity, string where);
        Task<bool> Update(string sql, SugarParameter[] parameters = null);
        Task<bool> Update(object operateAnonymousObjects);
        Task<bool> Update(
          T entity,
          List<string> lstColumns = null,
          List<string> lstIgnoreColumns = null,
          string where = ""
            );
        Task<bool> Delete(T entity);
        Task<bool> DeleteById(object id);
        Task<bool> DeleteByIds(object[] ids);
        Task<List<T>> Query();
        Task<List<T>> Query(string where);
        Task<List<T>> Query(Expression<Func<T, bool>> whereExpression);
        Task<List<TResult>> Query<TResult>(Expression<Func<T, TResult>> expression);
        Task<List<TResult>> Query<TResult>(Expression<Func<T, TResult>> expression, Expression<Func<T, bool>> whereExpression, string orderByFields);
        Task<List<T>> Query(Expression<Func<T, bool>> whereExpression, string orderByFields);
        Task<List<T>> Query(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression, bool isAsc = true);
        Task<List<T>> Query(string where, string orderByFields);
        Task<List<T>> Query(
            Expression<Func<T, bool>> whereExpression,
            int top,
            string orderByFields);
        Task<List<T>> Query(
            string where,
            int top,
            string orderByFields);
        Task<List<T>> QuerySql(string sql, SugarParameter[] parameters = null);
        Task<DataTable> QueryTable(string sql, SugarParameter[] parameters = null);
        Task<List<T>> Query(
            Expression<Func<T, bool>> whereExpression,
            int pageIndex,
            int pageSize,
            string orderByFields);
        Task<List<T>> Query(
          string where,
          int pageIndex,
          int pageSize,

          string orderByFields);

        Task<PageList<T>> QueryPage(Expression<Func<T, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, string? orderByFields = null);
        Task<List<TResult>> QueryMuch<T, T2, T3, TResult>(
            Expression<Func<T, T2, T3, object[]>> joinExpression,
            Expression<Func<T, T2, T3, TResult>> selectExpression,
            Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new();
        Task<PageList<TResult>> QueryTabsPage<T, T2, TResult>(
            Expression<Func<T, T2, object[]>> joinExpression,
            Expression<Func<T, T2, TResult>> selectExpression,
            Expression<Func<TResult, bool>> whereExpression,
            int pageIndex = 1,
            int pageSize = 20,
            string? orderByFields = null);
        Task<PageList<TResult>> QueryTabsPage<T, T2, TResult>(
            Expression<Func<T, T2, object[]>> joinExpression,
            Expression<Func<T, T2, TResult>> selectExpression,
            Expression<Func<TResult, bool>> whereExpression,
            Expression<Func<T, object>> groupExpression,
            int pageIndex = 1,
            int pageSize = 20,
            string? orderByFields = null);
    }
}
